package com.ys.tdm.service.doc.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.ys.tdm.bean.doc.Doc;
import com.ys.tdm.dao.doc.IDocDao;
import com.ys.tdm.service.doc.IDocService;
import com.ys.tdm.util.PagerModel;
import com.ys.tdm.util.Query;
import com.ys.tdm.util.StringTools;




/**
 * 模块信息Service实现
 * @author Troy
 * @date 2018-01-02 09:25:58
 */
@Service
public class DocServiceImpl implements IDocService {

	@Resource
	private IDocDao docDao;

	@Override
	public Doc getDocById(String id) throws Exception {
		return StringUtils.isNotBlank(id) ? this.docDao.getDocById(id.trim()) : null;
	}

	@Override
	public List<Doc> getDocByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		return StringUtils.isNotBlank(ids) ? this.docDao.getDocByIds(ids) : null;
	}
	
	@Override
	public List<Doc> getDocByIdsList(List<String> ids) throws Exception {
		return CollectionUtils.isNotEmpty(ids) ? this.docDao.getDocByIdsList(ids) : null;
	}

	@Override
	public List<Doc> getAll(Doc doc) throws Exception {
		return null != doc ? this.docDao.getAll(doc) : null;
	}

	@Override
	public int getByPageCount(Doc doc)throws Exception {
		return (null != doc) ? this.docDao.getByPageCount(doc) : 0;
	}

	@Override
	public void insertDoc(Doc doc) throws Exception {
		this.docDao.insertDoc(doc);
	}
	
	@Override
	public void insertDocBatch(List<Doc> docs) throws Exception {
		this.docDao.insertDocBatch(docs);
	}
	
	@Override
	public void delDocById(String id) throws Exception {
		if (StringUtils.isNotBlank(id)) {
			this.docDao.delDocById(id.trim());
		}
	}
	
	@Override
	public void delDocByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		if(StringUtils.isNotBlank(ids)){
			this.docDao.delDocByIds(ids);
		}
	}
	
	@Override
	public void delDocByIdsList(List<String> ids) throws Exception {
		if(CollectionUtils.isNotEmpty(ids)){
			this.docDao.delDocByIdsList(ids);
		}
	}

	@Override
	public int updateDoc(Doc doc) throws Exception {
		return this.docDao.updateDoc(doc);
	}
	
	@Override
	public int updateDocByIds(String ids,Doc doc) throws Exception {
		return this.docDao.updateDocByIds(ids, doc);
	}
	
	@Override
	public int updateDocByIdsList(List<String> ids,Doc doc) throws Exception {
		return this.docDao.updateDocByIdsList(ids, doc);
	}
	
	@Override
	public int updateDocList(List<Doc> docs) throws Exception {
		return this.docDao.updateDocList(docs);
	}
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成"'1','2','3','4'..."这种形式
	 * @param strs
	 * @return
	 
	private String converString(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				StringBuffer sbf = new StringBuffer("");
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						sbf.append("'").append(str.trim()).append("'").append(",");
					}
				}
				if (sbf.length() > 0) {
					sbf = sbf.deleteCharAt(sbf.length() - 1);
					return sbf.toString();
				}
			}
		}
		return "";
	}*/
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成List<String> 集合
	 * 
	 * @param strs
	 * @return
	 
	private List<String> converStringToList(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				List<String> strsList = new ArrayList<String>();
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						strsList.add(str.trim());
					}
				}
				if (strsList.size() > 0) {
					return strsList;
				}
			}
		}
		return null;
	}
	*/
	
	//------------api------------
	
}

